
BossMove = class("BossMove");





function BossMove:ctor()
    self.EnemyType={
        Enter=0,
        Attack=1,
        idle=2,
        move=3,
        }
    self.enemyType=0;
    self.flySpeed = 20;
    self.lateTime=1;
    self.StateTime=0;
    self.Hp=5;
    self.screenMax = Camera.main:ScreenToWorldPoint(Vector3(Screen.width, Screen.height));
    self.maxX = self.screenMax.x;
    self.maxY = self.screenMax.y;
    self.gameObject=newObject(ThunderManager.prefabs[4]);
    self.transform=self.gameObject.transform;
    self.firePos=self.transform:Find("firePos");
    self.luaTrigger = self.gameObject:AddComponent(typeof(LuaRigidTrigger));
    self.luaTrigger:AddHandler(self.OnTriggerEnter2D,self);
    self.transform.position=Vector3(0,6,-9);
    self.rigid=self.gameObject:GetComponent('Rigidbody2D');
 
    UpdateBeat:Add(self.Update,self);
end
function BossMove:Update()
    
    if(self.enemyType==self.EnemyType.Enter)then
        self:Enter()
    elseif(self.enemyType==self.EnemyType.Attack)then
        self:Attack()
    
    elseif(self.enemyType==self.EnemyType.idle)then
        self:idle();
        
    elseif(self.enemyType==self.EnemyType.move)then
        self:move();
    end
end



function BossMove:ChickFire()
    self.lateTime=Time.deltaTime+self.lateTime;
    if(self.lateTime>0.5)then
        self.lateTime=0;
    
        EnemyBulletMove.new(self.firePos,20,5);
end

end

function BossMove:OnTriggerEnter2D(collider)
    if(collider.tag=="Player")then
        PlayerMove.Hurt();
    end
    if(collider.tag=="PlayerBullet")then
        self.Hp=self.Hp-1;
        destroy(collider.gameObject);
        if(self.Hp==0)then
            UpdateBeat:Remove(self.Update,self);
            destroy(self.gameObject);
            ThunderManager.ScoreAdd(5)
        end 
    end
end


function BossMove:ChilkState()
    if(self.enemyType==3)then
        self.enemyType=0;
    end
    self.enemyType=self.enemyType+1;
end

function BossMove:Enter()
    self.rigid.velocity=Vector3.down * 1 ;
    if(self.transform.position.y<=3)then
    
       
        if(self.transform.position.x < 0)then
            self.rigid.velocity = Vector3.right*1;
        elseif(self.transform.position.x >= 0)then
            self.rigid.velocity = Vector3.left*1;
            

            self:ChilkState();
        end
      
    end
end
function BossMove:Attack()
    self:ChickFire();
    if (self.transform.position.x >= 1.9 or self.transform.position.x <= -1.9)then
        if (self.transform.position.x < 0)then
            self.rigid.velocity = Vector3.right;
        elseif(self.transform.position.x >= 0)then
            self.rigid.velocity = Vector3.left;
        end
    end
    self.StateTime=self.StateTime+Time.deltaTime;
    if (self.StateTime>=3) then
       self.StateTime=0;
       self:ChilkState();
    end

end
function BossMove:idle()
    self.StateTime=self.StateTime+Time.deltaTime;
    if (self.transform.position.x >= 1.9 or self.transform.position.x <= -1.9)then
        if (self.transform.position.x < 0)then
            self.rigid.velocity = Vector3.right;
        elseif(self.transform.position.x >= 0)then
            self.rigid.velocity = Vector3.left;
        end
    end
    if (self.StateTime>=3) then
       self.StateTime=0;
       self:ChilkState();
    end
end
function BossMove:move()
    self.rigid.velocity=Vector3.right * 1 ;
    if (self.transform.position.x >= 1.9 or self.transform.position.x <= -1.9)then
        
        if (self.transform.position.x < 0)then
            self.rigid.velocity = Vector3.right;
        elseif(self.transform.position.x >= 0)then
            self.rigid.velocity = Vector3.left;

            self:ChilkState();
        end
    end
end
